package com.xuanyuan.controller;

import com.xuanyuan.entity.Users;
import com.xuanyuan.service.UsersService;
import com.xuanyuan.utils.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController //控制类：异步请求
public class UsersController {

    //诸如业务层  ctrl+alt+b  interface
    @Resource
    private UsersService usersService;

    //异步请求的接口
    @RequestMapping("hrm/user/login")
    /*ResultVO返回给前端接口的对象*/
    @ResponseBody
    public ResultVO login(@RequestBody Users users){
        System.out.println(users.toString());
        //调用业务层代码
        return usersService.login(users.getuName(),users.getuPwd());
    }
//    @Autowired
//    private UserService userService;
//
//    // 查询所有用户数据
//    @GetMapping("/users/getAll")
//    @ResponseBody
//    public List<Users> getAllUsers(){
//        return this.userService.getAllUsers();
//    }

    @RequestMapping("/user/getList")
    /*ResultVO返回给前端接口的对象*/
    @ResponseBody
    public ResultVO getUserList(){
        ResultVO vo=new ResultVO();

        List<Users> usersList=usersService.getUserList();
        if(usersList!=null && usersList.size()>0){
            // 存储到Vo
            vo.setCode(200);
            vo.setData(usersList);
        }else {
            vo.setCode(500);
            vo.setData(null);
        }

        return  vo;
    }
}
